<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Spring Boot," />










<meta name="description" content="Spring Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能">
<meta name="keywords" content="Spring Boot">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring Boot自定义Starter">
<meta property="og:url" content="http://yoursite.com/2018/12/13/Spring-Boot自定义Starter/Spring-Boot自定义Starter/index.html">
<meta property="og:site_name" content="程序员乌托邦">
<meta property="og:description" content="Spring Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-13T13:02:50.068Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Spring Boot自定义Starter">
<meta name="twitter:description" content="Spring Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/12/13/Spring-Boot自定义Starter/Spring-Boot自定义Starter/"/>





  <title>Spring Boot自定义Starter | 程序员乌托邦</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">程序员乌托邦</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/13/Spring-Boot自定义Starter/Spring-Boot自定义Starter/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Wolf、Heart">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="程序员乌托邦">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Spring Boot自定义Starter</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-13T21:01:37+08:00">
                2018-12-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Spring-Boot/" itemprop="url" rel="index">
                    <span itemprop="name">Spring Boot</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="Spring-Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能"><a href="#Spring-Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能" class="headerlink" title="Spring Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能"></a>Spring Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能</h3><a id="more"></a>
<h1 id="一、Spring-Boot-Starter原理"><a href="#一、Spring-Boot-Starter原理" class="headerlink" title="一、Spring Boot Starter原理"></a>一、Spring Boot Starter原理</h1><p>Spring Boot本身定义了各种各样的Starter，当我们需要的时候，我们只需要引入对应的Starter，然后在application.properties中配置下属性就可以快速使用了，我们之所以可以快速使用，是因为Sping Boot的spring-boot-autoconfigure中的spring.factories定义了很多自动配置的类<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">org.springframework.boot.autoconfigure.EnableAutoConfiguration=\</span><br><span class="line">org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.cloud.CloudServiceConnectorsAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\</span><br><span class="line">org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\</span><br></pre></td></tr></table></figure></p>
<p>以上我们可以看到elasticsearch、redis等自动配置的类，这里我们打开RedisAutoConfiguration类<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">@ConditionalOnClass(RedisOperations.class)</span><br><span class="line">@EnableConfigurationProperties(RedisProperties.class)</span><br><span class="line">@Import(&#123; LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class &#125;)</span><br><span class="line">public class RedisAutoConfiguration &#123;</span><br><span class="line"></span><br><span class="line">	@Bean</span><br><span class="line">	@ConditionalOnMissingBean(name = &quot;redisTemplate&quot;)</span><br><span class="line">	public RedisTemplate&lt;Object, Object&gt; redisTemplate(</span><br><span class="line">			RedisConnectionFactory redisConnectionFactory) throws UnknownHostException &#123;</span><br><span class="line">		RedisTemplate&lt;Object, Object&gt; template = new RedisTemplate&lt;&gt;();</span><br><span class="line">		template.setConnectionFactory(redisConnectionFactory);</span><br><span class="line">		return template;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	@Bean</span><br><span class="line">	@ConditionalOnMissingBean</span><br><span class="line">	public StringRedisTemplate stringRedisTemplate(</span><br><span class="line">			RedisConnectionFactory redisConnectionFactory) throws UnknownHostException &#123;</span><br><span class="line">		StringRedisTemplate template = new StringRedisTemplate();</span><br><span class="line">		template.setConnectionFactory(redisConnectionFactory);</span><br><span class="line">		return template;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>可以看到该类上有很多的注解<br>@Configuration：代表这是一个配置类<br>@ConditionalOnClass(RedisOperations.class)：代表当RedisOperations存在的时候该类才自动执行自动配置<br>@EnableConfigurationProperties(RedisProperties.class)：表示启用RedisProperties<br>@Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class })：表示引入这两个类</p>
<p>接下来我们打开RedisProperties这个类<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br></pre></td><td class="code"><pre><span class="line">@ConfigurationProperties(prefix = &quot;spring.redis&quot;)</span><br><span class="line">public class RedisProperties &#123;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Database index used by the connection factory.</span><br><span class="line">	 */</span><br><span class="line">	private int database = 0;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Connection URL. Overrides host, port, and password. User is ignored. Example:</span><br><span class="line">	 * redis://user:password@example.com:6379</span><br><span class="line">	 */</span><br><span class="line">	private String url;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Redis server host.</span><br><span class="line">	 */</span><br><span class="line">	private String host = &quot;localhost&quot;;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Login password of the redis server.</span><br><span class="line">	 */</span><br><span class="line">	private String password;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Redis server port.</span><br><span class="line">	 */</span><br><span class="line">	private int port = 6379;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Whether to enable SSL support.</span><br><span class="line">	 */</span><br><span class="line">	private boolean ssl;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * Connection timeout.</span><br><span class="line">	 */</span><br><span class="line">	private Duration timeout;</span><br><span class="line"></span><br><span class="line">	private Sentinel sentinel;</span><br><span class="line"></span><br><span class="line">	private Cluster cluster;</span><br><span class="line"></span><br><span class="line">	private final Jedis jedis = new Jedis();</span><br><span class="line"></span><br><span class="line">	private final Lettuce lettuce = new Lettuce();</span><br><span class="line"></span><br><span class="line">	public int getDatabase() &#123;</span><br><span class="line">		return this.database;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setDatabase(int database) &#123;</span><br><span class="line">		this.database = database;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public String getUrl() &#123;</span><br><span class="line">		return this.url;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setUrl(String url) &#123;</span><br><span class="line">		this.url = url;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public String getHost() &#123;</span><br><span class="line">		return this.host;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setHost(String host) &#123;</span><br><span class="line">		this.host = host;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public String getPassword() &#123;</span><br><span class="line">		return this.password;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setPassword(String password) &#123;</span><br><span class="line">		this.password = password;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public int getPort() &#123;</span><br><span class="line">		return this.port;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setPort(int port) &#123;</span><br><span class="line">		this.port = port;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public boolean isSsl() &#123;</span><br><span class="line">		return this.ssl;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setSsl(boolean ssl) &#123;</span><br><span class="line">		this.ssl = ssl;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setTimeout(Duration timeout) &#123;</span><br><span class="line">		this.timeout = timeout;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public Duration getTimeout() &#123;</span><br><span class="line">		return this.timeout;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public Sentinel getSentinel() &#123;</span><br><span class="line">		return this.sentinel;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setSentinel(Sentinel sentinel) &#123;</span><br><span class="line">		this.sentinel = sentinel;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public Cluster getCluster() &#123;</span><br><span class="line">		return this.cluster;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public void setCluster(Cluster cluster) &#123;</span><br><span class="line">		this.cluster = cluster;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public Jedis getJedis() &#123;</span><br><span class="line">		return this.jedis;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	public Lettuce getLettuce() &#123;</span><br><span class="line">		return this.lettuce;</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure></p>
<p>删减了部分代码，我们可以看到这个类上有一个@ConfigurationProperties(prefix = “spring.redis”)注解，说明这是一个配置类，可以通过application.properties来进行配置属性，该类的属性都是默认的</p>
<p>总结：定义Starter要点</p>
<ol>
<li>需要有一个自动配置的类</li>
<li>需要一个配合自动类的配置类</li>
</ol>
<h1 id="二、示例"><a href="#二、示例" class="headerlink" title="二、示例"></a>二、示例</h1><h2 id="定义boot-example-greeter项目"><a href="#定义boot-example-greeter项目" class="headerlink" title="定义boot-example-greeter项目"></a>定义boot-example-greeter项目</h2><ol>
<li><p>Greeter</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">public class Greeter &#123;</span><br><span class="line"></span><br><span class="line">    private GreeterConfig greeterConfig;</span><br><span class="line"></span><br><span class="line">    public Greeter(GreeterConfig greetingConfig) &#123;</span><br><span class="line">        this.greeterConfig = greetingConfig;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String greet(LocalDateTime localDateTime) &#123;</span><br><span class="line"></span><br><span class="line">        String name = greeterConfig.getUserName();</span><br><span class="line">        int hourOfDay = localDateTime.getHour();</span><br><span class="line"></span><br><span class="line">        if (hourOfDay &gt;= 5 &amp;&amp; hourOfDay &lt; 12) &#123;</span><br><span class="line">            return String.format(&quot;Hello %s, %s&quot;, name, greeterConfig.getMorningMessage());</span><br><span class="line">        &#125; else if (hourOfDay &gt;= 12 &amp;&amp; hourOfDay &lt; 17) &#123;</span><br><span class="line">            return String.format(&quot;Hello %s, %s&quot;, name, greeterConfig.getAfternoonMessage());</span><br><span class="line">        &#125; else if (hourOfDay &gt;= 17 &amp;&amp; hourOfDay &lt; 20) &#123;</span><br><span class="line">            return String.format(&quot;Hello %s, %s&quot;, name, greeterConfig.getEveningMessage());</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            return String.format(&quot;Hello %s, %s&quot;, name, greeterConfig.getNightMessage());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String greet() &#123;</span><br><span class="line">        return greet(LocalDateTime.now());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>GreeterConfig</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">public class GreeterConfig &#123;</span><br><span class="line"></span><br><span class="line">    private String userName;</span><br><span class="line"></span><br><span class="line">    private String morningMessage;</span><br><span class="line"></span><br><span class="line">    private String afternoonMessage;</span><br><span class="line"></span><br><span class="line">    private String eveningMessage;</span><br><span class="line"></span><br><span class="line">    private String nightMessage;</span><br><span class="line"></span><br><span class="line">    public String getUserName() &#123;</span><br><span class="line">        return userName;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setUserName(String userName) &#123;</span><br><span class="line">        this.userName = userName;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getMorningMessage() &#123;</span><br><span class="line">        return morningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setMorningMessage(String morningMessage) &#123;</span><br><span class="line">        this.morningMessage = morningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getAfternoonMessage() &#123;</span><br><span class="line">        return afternoonMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setAfternoonMessage(String afternoonMessage) &#123;</span><br><span class="line">        this.afternoonMessage = afternoonMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getEveningMessage() &#123;</span><br><span class="line">        return eveningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setEveningMessage(String eveningMessage) &#123;</span><br><span class="line">        this.eveningMessage = eveningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getNightMessage() &#123;</span><br><span class="line">        return nightMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setNightMessage(String nightMessage) &#123;</span><br><span class="line">        this.nightMessage = nightMessage;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>主要功能就是根据GreeterConfig中的配置属性来打招呼功能</p>
<h2 id="定义greeter-spring-boot-autoconfigure项目"><a href="#定义greeter-spring-boot-autoconfigure项目" class="headerlink" title="定义greeter-spring-boot-autoconfigure项目"></a>定义greeter-spring-boot-autoconfigure项目</h2><ol>
<li><p>GreeterAutoConfiguration</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">@EnableConfigurationProperties(GreeterProperties.class)</span><br><span class="line">@ConditionalOnClass(Greeter.class)</span><br><span class="line">public class GreeterAutoConfiguration &#123;</span><br><span class="line"></span><br><span class="line">    @Autowired</span><br><span class="line">    private GreeterProperties greeterProperties;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    @ConditionalOnMissingBean</span><br><span class="line">    public GreeterConfig greeterConfig() &#123;</span><br><span class="line">        GreeterConfig greeterConfig = new GreeterConfig();</span><br><span class="line"></span><br><span class="line">        String userName = greeterProperties.getUserName();</span><br><span class="line">        String morningMessage = greeterProperties.getMorningMessage();</span><br><span class="line">        String afternoonMessage = greeterProperties.getAfternoonMessage();</span><br><span class="line">        String eveningMessage = greeterProperties.getEveningMessage();</span><br><span class="line">        String nightMessage = greeterProperties.getNightMessage();</span><br><span class="line"></span><br><span class="line">        greeterConfig.setUserName(userName);</span><br><span class="line">        greeterConfig.setMorningMessage(morningMessage);</span><br><span class="line">        greeterConfig.setAfternoonMessage(afternoonMessage);</span><br><span class="line">        greeterConfig.setEveningMessage(eveningMessage);</span><br><span class="line">        greeterConfig.setNightMessage(nightMessage);</span><br><span class="line">        return greeterConfig;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    @ConditionalOnMissingBean</span><br><span class="line">    public Greeter greeter() &#123;</span><br><span class="line">        Greeter greeter = new Greeter(greeterConfig());</span><br><span class="line">        return greeter;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>GreeterProperties</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">@ConfigurationProperties(prefix = &quot;com.boot.example&quot;)</span><br><span class="line">public class GreeterProperties &#123;</span><br><span class="line"></span><br><span class="line">    private String userName = &quot;本机用户&quot;;</span><br><span class="line"></span><br><span class="line">    private String morningMessage = &quot;早上好&quot;;</span><br><span class="line"></span><br><span class="line">    private String afternoonMessage = &quot;中午好&quot;;</span><br><span class="line"></span><br><span class="line">    private String eveningMessage = &quot;下午好&quot;;</span><br><span class="line"></span><br><span class="line">    private String nightMessage = &quot;晚上好&quot;;</span><br><span class="line"></span><br><span class="line">    public String getUserName() &#123;</span><br><span class="line">        return userName;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setUserName(String userName) &#123;</span><br><span class="line">        this.userName = userName;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getMorningMessage() &#123;</span><br><span class="line">        return morningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setMorningMessage(String morningMessage) &#123;</span><br><span class="line">        this.morningMessage = morningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getAfternoonMessage() &#123;</span><br><span class="line">        return afternoonMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setAfternoonMessage(String afternoonMessage) &#123;</span><br><span class="line">        this.afternoonMessage = afternoonMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getEveningMessage() &#123;</span><br><span class="line">        return eveningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setEveningMessage(String eveningMessage) &#123;</span><br><span class="line">        this.eveningMessage = eveningMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public String getNightMessage() &#123;</span><br><span class="line">        return nightMessage;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void setNightMessage(String nightMessage) &#123;</span><br><span class="line">        this.nightMessage = nightMessage;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>以上代码可以看到GreeterProperties类属于配置类，定义了默认的属性，也可以通过application.properties来指定</p>
<h2 id="定义greeting-spring-boot-starter项目"><a href="#定义greeting-spring-boot-starter项目" class="headerlink" title="定义greeting-spring-boot-starter项目"></a>定义greeting-spring-boot-starter项目</h2><ol>
<li>添加依赖<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencies&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;com.boot.example&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;greeter-spring-boot-autoconfigure&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">    &lt;/dependencies&gt;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h1 id="三、创建测试项目"><a href="#三、创建测试项目" class="headerlink" title="三、创建测试项目"></a>三、创建测试项目</h1><ol>
<li><p>添加依赖</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencies&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line"></span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;com.boot.example&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;greeting-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">    &lt;/dependencies&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>编写启动类</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">@SpringBootApplication</span><br><span class="line">public class CustomerStarterTestApplication implements CommandLineRunner &#123;</span><br><span class="line"></span><br><span class="line">    @Autowired</span><br><span class="line">    private Greeter greeter;</span><br><span class="line"></span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        SpringApplication.run(CustomerStarterTestApplication.class, args);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void run(String... args) throws Exception &#123;</span><br><span class="line">        System.out.println(&quot;【自定义Starter】：&quot; + greeter.greet());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动项目，可以看到如下输出结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">【自定义Starter】：Hello 本机用户, 晚上好</span><br></pre></td></tr></table></figure>
</li>
<li><p>编写配置属性来覆盖默认的配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">com.boot.example.userName=wids by properties</span><br><span class="line">com.boot.example.morningMessage=good morning by properties</span><br><span class="line">com.boot.example.afternoonMessage=good afternoon by properties</span><br><span class="line">com.boot.example.eveningMessage=good evening by properties</span><br><span class="line">com.boot.example.nightMessage=good night by properties</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动项目，可以看到如下输出结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">【自定义Starter】：Hello wids by properties, good night by properties</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过配置类的方式来覆盖默认属性</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">public class GreeterConfigure &#123;</span><br><span class="line"></span><br><span class="line">    @Bean</span><br><span class="line">    public GreeterConfig greeterConfig() &#123;</span><br><span class="line">        GreeterConfig greeterConfig = new GreeterConfig();</span><br><span class="line"></span><br><span class="line">        greeterConfig.setUserName(&quot;smile&quot;);</span><br><span class="line">        greeterConfig.setMorningMessage(&quot;good morning&quot;);</span><br><span class="line">        greeterConfig.setAfternoonMessage(&quot;good afternoon&quot;);</span><br><span class="line">        greeterConfig.setEveningMessage(&quot;good evening&quot;);</span><br><span class="line">        greeterConfig.setNightMessage(&quot;good night&quot;);</span><br><span class="line">        return greeterConfig;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动项目，可以看到如下输出结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">【自定义Starter】：Hello smile, good night</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>可以看到自定义Starter已经达到效果，和我们使用spring boot自带的Starter是一样的</p>
<h1 id="四、github代码"><a href="#四、github代码" class="headerlink" title="四、github代码"></a>四、github代码</h1><ul>
<li><a href="https://github.com/a601942905git/boot-example/tree/master/boot-example-custom-starter" target="_blank" rel="noopener">Spring Boot自定义Starter</a></li>
<li><a href="https://github.com/a601942905git/boot-example/tree/master/boot-example-custom-starter-test" target="_blank" rel="noopener">Spring Boot自定义Starter测试端</a></li>
</ul>
<h1 id="五、参考文献"><a href="#五、参考文献" class="headerlink" title="五、参考文献"></a>五、参考文献</h1><ul>
<li><a href="https://www.baeldung.com/spring-boot-custom-starter" target="_blank" rel="noopener">Creating a Custom Starter with Spring Boot</a></li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Spring-Boot/" rel="tag"># Spring Boot</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/12/13/Spring-Boot自定义错误页面/Spring-Boot自定义错误页面/" rel="next" title="Spring Boot自定义错误页面">
                <i class="fa fa-chevron-left"></i> Spring Boot自定义错误页面
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/18/Spring-Boot-Security入门/Spring-Boot-Security入门/" rel="prev" title="Spring Boot Security入门">
                Spring Boot Security入门 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Wolf、Heart</p>
              <p class="site-description motion-element" itemprop="description">主要用于分享平时学习的只是以及遇到的困难，帮助自己以及需要的人一起共同成长</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">45</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">14</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Spring-Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能"><span class="nav-number">1.</span> <span class="nav-text">Spring Boot自定义Starter，并可以通过配置文件和配置类来达到覆盖默认属性的功能</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一、Spring-Boot-Starter原理"><span class="nav-number"></span> <span class="nav-text">一、Spring Boot Starter原理</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、示例"><span class="nav-number"></span> <span class="nav-text">二、示例</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#定义boot-example-greeter项目"><span class="nav-number"></span> <span class="nav-text">定义boot-example-greeter项目</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#定义greeter-spring-boot-autoconfigure项目"><span class="nav-number"></span> <span class="nav-text">定义greeter-spring-boot-autoconfigure项目</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#定义greeting-spring-boot-starter项目"><span class="nav-number"></span> <span class="nav-text">定义greeting-spring-boot-starter项目</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、创建测试项目"><span class="nav-number"></span> <span class="nav-text">三、创建测试项目</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#四、github代码"><span class="nav-number"></span> <span class="nav-text">四、github代码</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#五、参考文献"><span class="nav-number"></span> <span class="nav-text">五、参考文献</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Wolf、Heart</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
